package logic

import (
	"context"
	"srv/model/mysql"

	"srv/internal/svc"
	"srv/renrenzu"

	"github.com/zeromicro/go-zero/core/logx"
)

type UserListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewUserListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserListLogic {
	return &UserListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *UserListLogic) UserList(in *renrenzu.UserListRequest) (*renrenzu.UserListResponse, error) {
	// todo: add your logic here and delete this line
	u := mysql.Users{}
	list, err := u.UserList(int(in.UserState))
	if err != nil {
		return nil, err
	}
	lists := []*renrenzu.UserList{}
	for _, v := range list {
		lists = append(lists, &renrenzu.UserList{
			Phone:     v.Phone,
			Password:  v.Password,
			UserState: int64(v.UserState),
		})
	}

	return &renrenzu.UserListResponse{List: lists}, nil
}
